package edu.sandau.basic.controller;

import edu.sandau.basic.domain.Menu;
import edu.sandau.basic.service.MenuService;
import edu.sandau.basic.vo.BasicMsg;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/api/menus")
@Tag(name = "菜单管理", description = "菜单的增删改查接口")
public class MenuController {

    @Resource
    private MenuService menuService;

    @GetMapping
    @Operation(summary = "获取所有菜单")
    public List<Menu> listMenus() {
        return menuService.listAll();
    }

    @GetMapping("/{id}")
    @Operation(summary = "根据ID查询菜单")
    public Menu getMenu(@PathVariable Integer id) {
        return menuService.getById(id);
    }

    @PostMapping
    @Operation(summary = "新增菜单（menu_id 自动生成）")
    public BasicMsg addMenu(@RequestBody Menu menu) {
        return menuService.add(menu);
    }

    @PutMapping
    @Operation(summary = "修改菜单")
    public BasicMsg updateMenu(@RequestBody Menu menu) {
        return menuService.update(menu);
    }

    @DeleteMapping("/{id}")
    @Operation(summary = "根据ID删除菜单")
    public BasicMsg deleteMenu(@PathVariable Integer id) {
        return menuService.delete(id);
    }
}
